﻿Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sexo() As String = {"M", "F"}
        Dim titulo() As String = {"PROGRAMADOR", "ANALISTA", "INGENIERO"}
        cmbsex.Items.AddRange(sexo)
        cmbtitulo.Items.AddRange(titulo)
        cmbsex.Text = cmbsex.Items.Item(0)
        cmbtitulo.Text = cmbtitulo.Items.Item(0)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        txtRut.Clear()
        txtNombre.Clear()
        txtSueldo.Clear()
        cmbsex.Text = cmbsex.Items.Item(0)
        cmbtitulo.Text = cmbtitulo.Items.Item(0)
        txtRut.Focus()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If IsNothing(txtRut.Text) Or IsNothing(txtNombre.Text) Or IsNothing(txtSueldo.Text) Then
            ErrorProvider1.SetError(Button1, "ingrese datos en todo los campos")
            txtRut.Focus()
        Else
            Dim nvoprofesor As New profesor(txtRut.Text, txtNombre.Text, cmbsex.SelectedIndex, cmbtitulo.SelectedIndex, txtSueldo.Text)
            arrprofe.Add(nvoprofesor)
            MsgBox("Datos Ingresados Correctamente", MsgBoxStyle.Exclamation)
            limpia()
        End If
    End Sub

    Sub limpia()
        txtRut.Clear()
        txtNombre.Clear()
        txtSueldo.Clear()
        cmbsex.Text = cmbsex.Items.Item(0)
        cmbtitulo.Text = cmbtitulo.Items.Item(0)
        txtRut.Focus()
    End Sub

    '=========================================================

    Private Sub txtNombre_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtNombre.Validating
        ErrorProvider1.Clear()
        If IsNumeric(txtNombre.Text) Then
            ErrorProvider1.SetError(txtNombre, "Nombre no es un valor numerico")
            txtNombre.Focus()
        Else
            ErrorProvider1.Clear()
        End If
    End Sub

    Private Sub txtSueldo_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtSueldo.Validating
        ErrorProvider1.Clear()
        If Not IsNumeric(txtSueldo.Text) Then
            ErrorProvider1.SetError(txtSueldo, "debe ingresar una nota válida")
        Else
            ErrorProvider1.Clear()
        End If
    End Sub

    Private Sub cmbsex_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cmbsex.Validating
        ErrorProvider1.Clear()
        If cmbsex.Text = "M" Or cmbsex.Text = "F" Then
            ErrorProvider1.Clear()
        Else
            ErrorProvider1.SetError(cmbsex, "debe ser M o F")
            cmbsex.Focus()
        End If
    End Sub

    Private Sub cmbtitulo_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cmbtitulo.Validating
        ErrorProvider1.Clear()
        If IsNumeric(cmbtitulo.Text) Then
            ErrorProvider1.SetError(cmbtitulo, "debe ingresar un título válida")
            cmbtitulo.Focus()
        Else
            ErrorProvider1.Clear()
        End If
    End Sub

End Class